# -*- coding: utf-8 -*-
"""
Created on Wed Apr 10 10:07:09 2024

@author: 刘翼
"""
import cv2
from matplotlib import pyplot as plt
# 全局阈值
img=cv2.imread(r"C:\Users\Public\opencv\Figure\butterfly.jpg",0) 
ret0,thresh0=cv2.threshold(img,127,255,cv2.THRESH_BINARY)

# 自适应阈值

ret1,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)

# Otus’s二值化

ret2,th2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)  # 全局阈值

# 先高斯滤波，高斯核的大小为（5,5），标准差为0
blur = cv2.GaussianBlur(img,(5,5),0)


# 显示图像
plt.subplot(221),plt.title('origin image')
plt.imshow(img)
plt.axis('off')

plt.subplot(222),plt.title('thresh0')
plt.imshow(thresh0)
plt.axis('off')

plt.subplot(223),plt.title('th1')
plt.imshow(th1)
plt.axis('off')

plt.subplot(224),plt.title('th2')
plt.imshow(th2)
plt.axis('off')
